<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>

<h:body>
	<h3>Mailing util</h3>
	
	<p:button value="Back to ticket page" outcome="ticket.jsf"/>

	<h:form>

		<h:panelGrid columns="2">
			<h:outputText value="Smtp server" />
			<p:inputText id="smtp" value="#{mailingBean.smtp}"></p:inputText>

			<h:outputText value="Port" />
			<p:inputText id="port" value="#{mailingBean.port}"></p:inputText>

			<h:outputText value="Login" />
			<p:inputText id="login" value="#{mailingBean.login}"></p:inputText>

			<h:outputText value="Password" />
			<p:password id="password" value="#{mailingBean.password}"></p:password>
		</h:panelGrid>
		<p:commandButton value="Collect" type="submit"
			action="#{mailingBean.collectMailList()}" ajax="false" />

		<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">

			<p:selectBooleanCheckbox value="#{mailingBean.groupByUser}" />
			<h:outputText value="One message to one email" />

		</h:panelGrid>

		<p:dataTable id="dataTable" var="notification"
			rendered="#{mailingBean.tableShown}"
			value="#{mailingBean.notificationDataModel}" paginator="true"
			rows="50" selection="#{mailingBean.selectedNotifications}">

			<f:facet name="header">  
	            Checkbox Based Selection  
	        </f:facet>

			<p:column selectionMode="multiple" style="width:2%" />

			<p:column headerText="№" style="width:2%">
				#{notification.id}  
			</p:column>

			<p:column headerText="User" style="width:18%">  
	            #{notification.email}  
	        </p:column>

			<p:column headerText="Message" style="width:20%">  
	            #{notification.message}  
	        </p:column>

			<p:column headerText="Assign date" style="width:24%">  
	            #{notification.assignedDate}  
	        </p:column>

			<p:column headerText="Last notification (Date)" style="width:24%">
				<h:panelGroup rendered="#{notification.lastNotification eq null}">
					<div align="center">-</div>
				</h:panelGroup>
	            #{notification.lastNotification}  
	        </p:column>

			<p:column headerText="Last notification (Result)" style="width:10%">
				<h:panelGroup
					rendered="#{notification.notificationResult.id eq 1}">
					<div align="center">
						<p:graphicImage value="succeed.ico">
						</p:graphicImage>
					</div>
				</h:panelGroup>

				<h:panelGroup rendered="#{notification.notificationResult.id eq 2}">
					<div align="center">
						<p:graphicImage value="failed.ico">
						</p:graphicImage>
					</div>
				</h:panelGroup>
				
				<h:panelGroup rendered="#{notification.notificationResult.id eq 3}">
					<div align="center">-</div>
				</h:panelGroup>
				
				<h:panelGroup rendered="#{notification.notificationResult.id eq 4}">
					<div align="center">
						<p:graphicImage value="partial.ico">
						</p:graphicImage>
					</div>
				</h:panelGroup>
			</p:column>
		</p:dataTable>
		<h:panelGroup rendered="#{mailingBean.tableShown}">
			<p:commandButton value="Send" type="submit" ajax="false"
				action="#{mailingBean.sendNotification()}" />
		</h:panelGroup>
	</h:form>
</h:body>

</html>